using System;
using System.Collections.Generic;
using System.Drawing;
using System.Data;

using Elev.Core.DAL;
using Elev.Core.Utility;

namespace Elev.Core
{
    public class ExamType : IDimension
    {
        int id;
        string name;
        int coefficient;
        Color displayColor;

        public int ID { get { return id; } }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Coefficient
        {
            get { return coefficient; }
            set { coefficient = value; }
        }

        public Color DisplayColor
        {
            get { return displayColor; }
            set { displayColor = value; }
        }

        public ExamType(DataRow row)
        {
            parse(row);
        }

        public ExamType() : this(-1, "", 1, Color.Black) { }

        public ExamType(int ID, string Name, int Coefficient, Color DisplayColor)
        {
            id = ID;
            name = Name;
            coefficient = Coefficient;
            displayColor = DisplayColor;
        }

        void parse(DataRow dr)
        {
            id = Convert.ToInt32(dr["ID"]);
            name = (string)dr["Name"];
            coefficient = Convert.ToInt32(dr["Coefficient"]);
            displayColor = ColorTools.FormatColor(Convert.ToInt32(dr["DisplayColor"]));
        }

        #region IDimension Members

        public int Save()
        {
            ExamTypeInternal examTypeInternal = new ExamTypeInternal();
            if (id == -1)
            {
                // New creation ...
                id = examTypeInternal.Add(name, coefficient, displayColor.ToArgb());
            }
            else
            {
                examTypeInternal.Update(id, name, coefficient, displayColor.ToArgb());
            }
            return id;
        }

        public void Delete()
        {
            ExamTypeInternal examTypeInternal = new ExamTypeInternal();
            examTypeInternal.Delete(id);
        }

        #endregion

        public override string ToString()
        {
            return name;
        }
    }
}
